﻿using System;
using System.Collections.Generic;
using System.Net.Mail;

namespace AppGauge.Msg
{
    public class Email
    {
        string _from;
        string _to;
        string _subject;
        string _body;

        public struct connection
        {
           public string ServerHost;
            public int port;
            public string UserName;
            public string Password;
        }

        public struct attachment
        {
            string _fileName;
            string _localName;
            string _contentType;
        }


        public Email()
        {
        }

        public Email(string EmailFrom, string EmailTo)
        {
            fromAddr = EmailFrom;
            toAddr = EmailTo;
        }

        public Email(string From, string To, string Subject, string Body)
        {
            fromAddr = From;
            toAddr = To;
            subject = Subject;
            body = Body;
        }

        public Email(string From, string To, string Subject, string Body,string ServerHost,int Port)
        {
            fromAddr = From;
            toAddr = To;
            subject = Subject;
            body = Body;
        }

        
        public string fromAddr
        {
            get { return _from; }
            set
            {
                if(IsEmailId(value))
                    _from = value;
            }
        }

        public string toAddr
        {
            get { return _to; }
            set
            {
                if (IsEmailId(value))
                    _to = value;
            }
        }

        public string subject
        {
            get { return _subject; }
            set
            {
                if (value.Length < 20)
                    _subject = value;
            }
        }

        public string body
        {
            get { return _body; }
            set{
                if (value.Length < 2000)
                    _body = value;
            }
        }

        //Need Regex Validation Checking, and possibly MX Record Lookup :P
        private bool IsEmailId(string EmailId)
        {
            if (EmailId.Length > 5 && EmailId.Length < 150 && EmailId.Contains("@"))
                return true;
            else
                return false;
        }
    }
}
